﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using Microsoft.Practices.Unity;

namespace Infrastructure.Aspect.Patterns
{
    //public class UnityContainerSingleton
    //{
    //    private static IUnityContainer _instance;
    //    private static object Lock = new object();
    //    public static IUnityContainer Instance { get {
    //        lock (Lock)
    //        {
    //            if (_instance == null)
    //            {
    //                _instance = new UnityContainer();
    //            }
    //        }
    //        return _instance;
    //    } }
    //}
    public class Singleton<T, I>
        where T : I, new()
 
    {
        private static volatile object _instance;
        private static object Lock = new object();
        public static I Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (Lock)
                    {
                        if (_instance == null)
                        {
                            _instance = new T();
                        }
                    }
                }
                return (I)_instance;
            }
        }
    }
    public class Singleton<T> where T : new()
    {
        private static volatile  object _instance;
        private static object Lock = new object();
        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (Lock)
                    {
                        if (_instance == null)
                        {
                            _instance = new T();
                        }
                    }
                }
                return (T)_instance;
            }            
        }

    }
}
